<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<script language="javascript">
	$().ready( function() {
		$(":input[name*='ProdId']").each(function(){
			$("#" + this.id).numeric();
			$(this).blur(function(){
				$(this).val(prodPadLeft($(this).val()));
				getProductInfo("${midContextPath}",this.id + "_ProdName",$(this).val());
			});
		});
	
					
		$('#startDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDate').datepick({minDate: new Date(),showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		$('#childCate').hide();	
		$("#advType").change(function(){
			if ( $("#advType").val() == "100_PROMOTION"){
				$('#childCate').show();
				initLevel();
			}else
				$('#childCate').hide();		
		});
		
		initLevel();
		
		$("#mainCateId").change(function(){
			initLevel();
		});

		$("#subBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("10");
				$("#cateMainProdAdvForm").submit();
			}
		});

		$("#draftBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("00");
				$("#cateMainProdAdvForm").submit();
			}
		});
		$("#canBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("90");
				$("#cateMainProdAdvForm").submit();
			}
		});
	});

	function initLevel(){
		if ( $("#advType").val() == "100_PROMOTION" ){
			$('#childCate').show();
			var childCateIds = "<option value=''>====== 请选择  ======</option>";
			$.getJSON("${midContextPath}/category/getProductCategory.do?type=json",
					{categoryid:$("#mainCateId").val()},
					function(categories){
						for(var i = 0 ; i < categories.length; i++ ){
							if ( "${position.childCateId}" == categories[i].id )
								childCateIds = childCateIds + "<option value='" + categories[i].id + "' selected='selected'>" + categories[i].name + "</option>";
							else
								childCateIds = childCateIds + "<option value='" + categories[i].id + "'>" + categories[i].name + "</option>";
						}
						$("#childCateId").find('option').remove().end();
						$("#childCateId").html(childCateIds);
					});
		}else{
			$("#childCateId").find('option').remove().end();
		}
	}

	function validate_data(){
		if ( $("#advName").val() == "" ){
			alert("请输入广告名称");
			$("#advName").focus();
			return false;
		}
		if ( $("#advType").val() == "" ){
			alert("请选择广告类型");
			$("#advType").focus();
			return false;
		}
		if ( $("#startDate").val() == ""){
			alert("请输入起始时间");
			$("#startDate").focus();
			return false;
		}

		if( $("#endDate").val() == "" ){
			alert("请输入结束时间");
			$("#endDate").focus();
			return false;
		}
		if (  $("#mainCateId").val() == "" ){
			alert("请选馆别");
			$("#mainCateId").focus();
			return false;
		}
		if ( $("#advType").val() == "100_PROMOTION"){
			if ( $("#childCateId").val() == "" ){
				alert("请选次分类");
				$("#childCateId").focus();
				return false;
			}
		}
		for( var i = 1; i <= 5; i++ ){
			if ( $("#tab" + i + "Title").val() == "" ){
				alert("请输入tab" + i + "标题文字");
				$("#tab" + i + "Title").focus();
				return false;
			}
			for( var j = 1; j <=3; j++ ){
				if ( $("#tab" + i + "ProdId" + j).val() == ""){
					alert("请输入tab" + i + " 主打商品"+ j +"编号" );
					$("#tab" + i + "ProdId" + j).focus();
					return false;
				}
			}
		}
		return true;
	}
</script>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<h1>广告管理</h1>
<s:form action="cateMainProd/saveCateMainProdAdv.do" name="cateMainProdAdvForm" id="cateMainProdAdvForm">
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th>广告名称</th>
				<td><input type="text" id="advName" name="advName" value="${advName}" size="30" maxlength="30"/></td>
				<th>类型</th>
				<td>
					<c-rt:if test="${advType eq '000_PROMOTION'}">馆首页主打商品</c-rt:if>
					<c-rt:if test="${advType eq '100_PROMOTION'}">分类页主打商品</c-rt:if>
					<input type="hidden" id="advType" name="advType" value="${advType}"/>
			</tr>
			<tr>
				<th>起迄时间</th>
				<td colspan="3">
				<!-- 
				<c-rt:choose>
					<c-rt:when test="${not empty advertise.id}">
						${startDate} ~ 
						<input type="hidden" id="startDate" name="startDate" value="${startDate}"/>
					</c-rt:when>
					<c-rt:otherwise>
						
					</c-rt:otherwise>
				</c-rt:choose>
				 -->
				<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/> ~ 
				<input type="text" id="endDate" name="endDate" value="${endDate}" maxlength="10"/>
				</td>
			</tr>
			<tr>
				<th>馆别</th>
				<td>
					<select id="mainCateId" name="mainCateId">
						<option value="">====== 请选择  ======</option>
						<c-rt:forEach items="${categoryRoot}" var="category">
							<option value="${category.id}" ${position.mainCateId eq category.id ? "selected" : ""}>${category.name}</option>
						</c-rt:forEach>
					</select>
					<div id="childCate">
						<select id="childCateId" name="childCateId">
							<option value="">====== 请选择  ======</option>
						</select>
					</div>
				</td>
				<th>位置</th>
				<td>
					<select id="advTarget" name="advTarget">
						<option value="TOP"  ${advTarget eq "TOP" ? "selected" : ""}>上</option>
						<option value="MID" ${advTarget eq "MID" ? "selected" : ""}>中</option>
						<option value="BTM" ${advTarget eq "BTM" ? "selected" : ""}>下</option>
					</select>
				</td>
			</tr>
		</tbody>
	</table>
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th colspan="6">tab1设定</th>
			</tr>
			<tr>
				<th>Tab 标题文字</th>
				<td colspan="5"><input type="text" name="tab1Title" id="tab1Title" maxlength="4" size="10" value="${tab1Title}"/>范例:热荐商品/促销专题/本周热推/打折特卖/疯狂热卖,<span class="txt-rd">字数限制:4个中文字</span></td>
			</tr>
			<tr>
				<th>主打商品一</th>
				<td><input type="text" name="tab1ProdId1" id="tab1ProdId1" maxlength="8" value="${tab1ProdId1}"/><br/>（请输入商品编号）<br/><span id="tab1ProdId1_ProdName"></span><br/></td>
				<th>主打商品二</th>
				<td><input type="text" name="tab1ProdId2" id="tab1ProdId2" maxlength="8" value="${tab1ProdId2}"/><br/>（请输入商品编号）<br/><span id="tab1ProdId2_ProdName"></span><br/></td>
				<th>主打商品三</th>
				<td><input type="text" name="tab1ProdId3" id="tab1ProdId3" maxlength="8" value="${tab1ProdId3}"/><br/>（请输入商品编号）<br/><span id="tab1ProdId3_ProdName"></span><br/></td>
			</tr>
			<tr>
				<th colspan="6">tab2设定</th>
			</tr>
			<tr>
				<th>Tab 标题文字</th>
				<td colspan="5"><input type="text" name="tab2Title" id="tab2Title" maxlength="4" size="10" value="${tab2Title}"/>范例:热荐商品/促销专题/本周热推/打折特卖/疯狂热卖,<span class="txt-rd">字数限制:4个中文字</span></td>
			</tr>
			<tr>
				<th>主打商品一</th>
				<td><input type="text" name="tab2ProdId1" id="tab2ProdId1" maxlength="8" value="${tab2ProdId1}"/><br/>（请输入商品编号）<br/><span id="tab2ProdId1_ProdName"></span><br/></td>
				<th>主打商品二</th>
				<td><input type="text" name="tab2ProdId2" id="tab2ProdId2" maxlength="8" value="${tab2ProdId2}"/><br/>（请输入商品编号）<br/><span id="tab2ProdId2_ProdName"></span><br/></td>
				<th>主打商品三</th>
				<td><input type="text" name="tab2ProdId3" id="tab2ProdId3" maxlength="8" value="${tab2ProdId3}"/><br/>（请输入商品编号）<br/><span id="tab2ProdId3_ProdName"></span><br/></td>
			</tr>
			<tr>
				<th colspan="6">tab3设定</th>
			</tr>
			<tr>
				<th>Tab 标题文字</th>
				<td colspan="5"><input type="text" name="tab3Title" id="tab3Title" maxlength="4" size="10" value="${tab3Title}"/>范例:热荐商品/促销专题/本周热推/打折特卖/疯狂热卖,<span class="txt-rd">字数限制:4个中文字</span></td>
			</tr>
			<tr>
				<th>主打商品一</th>
				<td><input type="text" name="tab3ProdId1" id="tab3ProdId1" maxlength="8" value="${tab3ProdId1}"/><br/>（请输入商品编号）<br/><span id="tab3ProdId1_ProdName"></span><br/></td>
				<th>主打商品二</th>
				<td><input type="text" name="tab3ProdId2" id="tab3ProdId2" maxlength="8" value="${tab3ProdId2}"/><br/>（请输入商品编号）<br/><span id="tab3ProdId2_ProdName"></span><br/></td>
				<th>主打商品三</th>
				<td><input type="text" name="tab3ProdId3" id="tab3ProdId3" maxlength="8" value="${tab3ProdId3}"/><br/>（请输入商品编号）<br/><span id="tab3ProdId3_ProdName"></span><br/></td>
			</tr>
			<tr>
				<th colspan="6">tab4设定</th>
			</tr>
			<tr>
				<th>Tab 标题文字</th>
				<td colspan="5"><input type="text" name="tab4Title" id="tab4Title" maxlength="4" size="10" value="${tab4Title}"/>范例:热荐商品/促销专题/本周热推/打折特卖/疯狂热卖,<span class="txt-rd">字数限制:4个中文字</span></td>
			</tr>
			<tr>
				<th>主打商品一</th>
				<td><input type="text" name="tab4ProdId1" id="tab4ProdId1"  maxlength="8" value="${tab4ProdId1}"/><br/>（请输入商品编号）<br/><span id="tab4ProdId1_ProdName"></span><br/></td>
				<th>主打商品二</th>
				<td><input type="text" name="tab4ProdId2" id="tab4ProdId2" maxlength="8" value="${tab4ProdId2}"/><br/>（请输入商品编号）<br/><span id="tab4ProdId2_ProdName"></span><br/></td>
				<th>主打商品三</th>
				<td><input type="text" name="tab4ProdId3" id="tab4ProdId3" maxlength="8" value="${tab4ProdId3}"/><br/>（请输入商品编号）<br/><span id="tab4ProdId3_ProdName"></span><br/></td>
			</tr>
			<tr>
				<th colspan="6">tab5设定</th>
			</tr>
			<tr>
				<th>Tab 标题文字</th>
				<td colspan="5"><input type="text" name="tab5Title" id="tab5Title" maxlength="4" size="10" value="${tab5Title}"/>范例:热荐商品/促销专题/本周热推/打折特卖/疯狂热卖,<span class="txt-rd">字数限制:4个中文字</span></td>
			</tr>
			<tr>
				<th>主打商品一</th>
				<td><input type="text" name="tab5ProdId1" id="tab5ProdId1" maxlength="8" value="${tab5ProdId1}"/><br/>（请输入商品编号）<br/><span id="tab5ProdId1_ProdName"></span><br/></td>
				<th>主打商品二</th>
				<td><input type="text" name="tab5ProdId2" id="tab5ProdId2" maxlength="8" value="${tab5ProdId2}"/><br/>（请输入商品编号）<br/><span id="tab5ProdId2_ProdName"></span><br/></td>
				<th>主打商品三</th>
				<td><input type="text" name="tab5ProdId3" id="tab5ProdId3" maxlength="8" value="${tab5ProdId3}"/><br/>（请输入商品编号）<br/><span id="tab5ProdId3_ProdName"></span><br/></td>
			</tr>									
			<tr>
				<td colspan="4">
					<input type="hidden" id="advId" name="advId" value="${advId}"/>
					<input type="hidden" id="advStatus" name="advStatus" value="${advStatus}"/>
					<input type="button" id="subBtn" name="subBtn" value="发送"/>
					<input type="button" id="draftBtn" name="draftBtn" value="草稿"/>
					<input type="button" id="canBtn" name="canBtn" value="暂停"/>
				</td>
			</tr>												
		</tbody>
	</table>
</s:form>
<div class="f-link">
	<a href="${midContextPath}/generate/cateMainProd/search.do">回广告查询页</a>
</div>